<?php
require_once 'calendarSyncCommon.php';
set_time_limit(60000);
if(!isset($_SESSION['user_id'])){
    header("location: main.php");
}
if(isset($_POST['save'])){
    $syncQ = new gCalendarSyncQ($_SESSION['user_id']);
    $service = new CalendarSyncController($syncQ);
    
    $datetime = mktime($_POST["hour"], $_POST["min"], $_POST["sec"], $_POST["month"], $_POST["day"], $_POST["year"]);
    $service->FinishSync(true, $datetime);
}
else if(isset($_GET['current'])){
    $service = new SFGoogleContactSync($_SESSION['user_id']);
    
    $service->FinishSync(true);
}
?>
<html>
    <body>
        server timezone name: <?php echo date_default_timezone_get(); ?>
        <form method='POST'>
            <ul>
                <li><a href="test_updatelastsync.php?current=true">Update Last Sync Date to Current Datetime</a></li>
                <li>Specify a datetime:
                    <div>
                        <table>
                            <tr>
                                <td>Year</td>
                                <td>Month</td>
                                <td>Day</td>
                                <td>Hour</td>
                                <td>Min</td>
                                <td>Sec</td>
                            </tr>
                            <tr>
                                <td>
                                    <select id="year" name="year">
                                        <?php for($i=2000; $i<=2025; $i++){ ?>
                                            <option value="<?php echo $i ?>" <?php echo $i==date('Y')?'selected':'' ?>><?php echo $i ?></option>
                                        <?php } ?>
                                    </select>
                                </td>
                                <td>
                                    <select id="month" name="month">
                                        <?php for($i=1; $i<=12; $i++){ ?>
                                            <option value="<?php echo $i<10?'0'.$i:$i ?>" <?php echo $i==date('n')?'selected':'' ?>><?php echo $i<10?'0'.$i:$i ?></option>
                                        <?php } ?>
                                    </select>
                                </td>
                                <td>
                                    <select id="day" name="day">
                                        <?php for($i=1; $i<=31; $i++){ ?>
                                            <option value="<?php echo $i<10?'0'.$i:$i ?>" <?php echo $i==date('j')?'selected':'' ?>><?php echo $i<10?'0'.$i:$i ?></option>
                                        <?php } ?>
                                    </select>
                                </td>
                                <td>
                                    <select id="hour" name="hour">
                                        <?php for($i=0; $i<=23; $i++){ ?>
                                            <option value="<?php echo $i<10?'0'.$i:$i ?>" <?php echo $i==date('G')?'selected':'' ?>><?php echo $i<10?'0'.$i:$i ?></option>
                                        <?php } ?>
                                    </select>
                                </td>
                                <td>
                                    <select id="min" name="min">
                                        <?php for($i=0; $i<=59; $i++){ ?>
                                            <option value="<?php echo $i<10?'0'.$i:$i ?>" ><?php echo $i<10?'0'.$i:$i ?></option>
                                        <?php } ?>
                                    </select>
                                </td>
                                <td>
                                    <select id="sec" name="sec">
                                        <?php for($i=0; $i<=59; $i++){ ?>
                                            <option value="<?php echo $i<10?'0'.$i:$i ?>" ><?php echo $i<10?'0'.$i:$i ?></option>
                                        <?php } ?>
                                    </select>
                                </td>
                            </tr>
                        </table>
                    </div>
                </li>
            </ul>
            <input type="submit" value="Save" id="save" name="save"/>
        </form>
        <a href='main.php'>Back to Main</a>
    </body>
</html>